using System;
using System.Collections.Generic;
using System.Text;
using Sandia.MVCFramework.Request;

namespace Sandia.MVCFramework.Request
{
    /// <summary>
    /// A simple generic that creates a request having one parameter.
    /// </summary>
    /// <remarks>
    /// This class takes care both of the request and the underlying
    /// parameters.  The type specified is the single parameter that you
    /// can store in this request.  The class uses the ObjectParameter
    /// class to automatically generate the parameters.
    /// </remarks>
    /// <typeparam name="T"></typeparam>
    public class OneParameterRequest<T>: AbstractStandardRequest
    {
        /// <summary>
        /// Create a new request
        /// </summary>
        /// <param name="parameterData"></param>
        public OneParameterRequest(T parameterData)
        {
            parameters[typeof(T).FullName] = new ObjectParameter<T>(parameterData);
        }

        /// <summary>
        /// The parameter associated with this request
        /// </summary>
        /// <remarks>
        /// Expose this publicly as desired in a subclass with a semantically 
        /// meaningful name.
        /// </remarks>
        protected T Param1
        {
            get { return (T)parameters[typeof(T).FullName].Data; }
            set { parameters[typeof(T).FullName] = new ObjectParameter<T>(value); }
        }
            
        /// <summary>
        /// Set the parameters to null
        /// </summary>
        protected override void initParameters()
        {
            parameters[typeof(T).FullName] = null;
        }
    }
}
